package com.gxwzxy.medic.servlet;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BaseServlet
 */
public class BaseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取需要执行的类方法
		String method = req.getParameter("method");
		try {
			//获取当前请求的servlet类
			Class c = this.getClass();
			//通过反射获取到这个类的这个方法并传入形参
			Method m = c.getMethod(method, HttpServletRequest.class, HttpServletResponse.class);
			//执行这个类的方法
			m.invoke(this, req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
